$(function () {
    //数据表格
    var btn_datagrid = $("#btn_datagrid");
    btn_datagrid.datagrid({
        url:"/curriculum/list.do",//从远程站点请求数据
        fit:true,//面板大小将自适应父容器
        fitColumns:true,//自动展开/收缩列的大小
        striped:true,//显示斑马线效果
        pagination:true,//显示分页工具栏
        columns:[[
            {field:"id",checkbox:true},//复选框
            {field:"date",title:"日期",width:80},
            {field:"week",title:"星期",width:80},
            {field:"grade",title:"班级",width:80,formatter:function (value) {
                    return value ? value.className : "";
                }},
            {field:"course",title:"课程",width:80},
            {field:"charge",title:"班主任",width:80,formatter:function (value) {
                    return value ? value.username : "";
                }},
            {field:"teacher",title:"任课教师",width:80,formatter:function (value) {
                    return value ? value.username : "";
                }},
            {field:"remark",title:"备注",width:80}
        ]],
        toolbar:"#buttAll",
    })

    $("#btn_calendar").panel({
        width:380,
        height:370
    })


    //弹框
    btn_dialog = $("#btn_dialog");
    btn_dialog.dialog({
        width:260,
        height:200,
        buttons:"#btn_buttons",
        openAnimation:'show',
        closed:true
    })

    //高级查询框
    teacherId = $("#teacherId");
    gradeId = $("#gradeId");
    minTime = $("#minTime");
    maxTime = $("#maxTime");
    teacherId.combobox({
        url:'/employee/list.do',//远程加载所有员工
        valueField:'id',//数据值名称绑定到该下拉列表框
        textField:'username'//数据字段名称绑定到该下拉列表框
    })

    gradeId.combobox({
        url:'/grade/list.do',//远程加载所有班级
        valueField:'id',//数据值名称绑定到该下拉列表框
        textField:'className'//数据字段名称绑定到该下拉列表框
    })


    //高级查询方法
    methods = {
        query:function () {
            teacherIdValue = teacherId.combobox('getValue');
            gradeIdValue = gradeId.combobox('getValue');
            minTimeValue = minTime.combobox('getText');
            maxTimeValue = maxTime.combobox('getText');
            btn_datagrid.datagrid('load',{
                url:'/curriculum/list.do',
                gradeId:gradeIdValue,
                teacherId:teacherIdValue,
                minTime:minTimeValue,
                maxTime:maxTimeValue
            })
        },
        impot:function () {
            btn_dialog.dialog('open');
            btn_dialog.dialog('setTitle',"上传课程表");
        },
        save:function () {
            $("#myForm").form('submit',{
                url:'/curriculum/import.do',
                success:function (data) {
                    ndata = $.parseJSON(data)
                    if (ndata.success) {
                        $.messager.alert('温馨提示','上传成功');
                        btn_dialog.dialog('close');
                    }else {
                        $.messager.alert('警告',ndata.msg);
                        btn_dialog.dialog('close');
                    }
                }
            })
        }
    }

    //所有a标签点击事件触发的事件
    $("a[data-operation]").click(function () {
        met = $(this).data("operation");
        methods[met]();
    })


    $('#btn_calendar').calendar({
        width: 380,
        height: 320,
        data: [
            {
                date: '2017/12/24',
                value: 'Christmas Eve'
            },
            {
                date: '2017/12/25',
                value: 'Merry Christmas'
            },
            {
                date: '2017/01/01',
                value: 'Happy New Year'
            }
        ],
        onSelected: function (view, date, data) {
            // console.log('view:' + view)
            // alert('date:' + date)
            // console.log('data:' + (data || 'None'));

            var d = new Date(date);
            youWant=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
            btn_datagrid.datagrid('load',{
                url:'/curriculum/list.do',
                date:youWant
            })
        }
    });
    $('#dd').calendar({
        trigger: '#dt',
        zIndex: 999,
        format: 'yyyy-mm-dd',
        onSelected: function (view, date, data) {
            console.log('event: onSelected')
        },
        onClose: function (view, date, data) {
            console.log('event: onClose')
            console.log('view:' + view)
            console.log('date:' + date)
            console.log('data:' + (data || 'None'));
        }
    });
})